using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DataAccessLayer
{
    public class DAO_User
    {
        public static bool Insert(Object tmp)
        {
            USER obj = (USER)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@USER_ADDRESS", obj.USER_ADDRESS));
            _list.Add(new SqlParameter("@USER_BIRTHDATE", obj.USER_BIRTHDATE));
            _list.Add(new SqlParameter("@USER_EMAIL", obj.USER_EMAIL));
            _list.Add(new SqlParameter("@USER_FIRST_NAME", obj.USER_FIRST_NAME));
            _list.Add(new SqlParameter("@USER_ID", obj.USER_ID));
            _list.Add(new SqlParameter("@USER_LAST_NAME", obj.USER_LAST_NAME));
            _list.Add(new SqlParameter("@USER_MOBILE", obj.USER_MOBILE));

            int n = clsDataAccessHelper.ExecNonQuery("sp_user_insert", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static bool Update(Object tmp)
        {
            USER obj = (USER)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@USER_ADDRESS", obj.USER_ADDRESS));
            _list.Add(new SqlParameter("@USER_BIRTHDATE", obj.USER_BIRTHDATE));
            _list.Add(new SqlParameter("@USER_EMAIL", obj.USER_EMAIL));
            _list.Add(new SqlParameter("@USER_FIRST_NAME", obj.USER_FIRST_NAME));
            _list.Add(new SqlParameter("@USER_ID", obj.USER_ID));
            _list.Add(new SqlParameter("@USER_LAST_NAME", obj.USER_LAST_NAME));
            _list.Add(new SqlParameter("@USER_MOBILE", obj.USER_MOBILE));

            int n = clsDataAccessHelper.ExecNonQuery("sp_user_update", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static bool Delete(Object tmp)
        {
            USER obj = (USER)tmp;
            bool result = false;
            List<SqlParameter> _list = new List<SqlParameter>();
            _list.Add(new SqlParameter("@USER_ADDRESS", obj.USER_ADDRESS));
            _list.Add(new SqlParameter("@USER_BIRTHDATE", obj.USER_BIRTHDATE));
            _list.Add(new SqlParameter("@USER_EMAIL", obj.USER_EMAIL));
            _list.Add(new SqlParameter("@USER_FIRST_NAME", obj.USER_FIRST_NAME));
            _list.Add(new SqlParameter("@USER_ID", obj.USER_ID));
            _list.Add(new SqlParameter("@USER_LAST_NAME", obj.USER_LAST_NAME));
            _list.Add(new SqlParameter("@USER_MOBILE", obj.USER_MOBILE));

            int n = clsDataAccessHelper.ExecNonQuery("sp_user_delete", _list);
            if (n == 1)
                result = true;
            return result;
        }

        public static DataTable LoadAll()
        {
            return clsDataAccessHelper.ExecuteQuery("sp_user_get_all", null);
        }
    }
}
